<?php
session_start();
/*
 * Session variables:
 * $_SESSION['view_announcement'] [serial] = id of announcement acting on
 * $_SESSION['type'] [string] = user type of the logged in user
 * $_SESSION['authorised'] [boolean] = whether or not the current user is logged in
 */
if(isset($_SESSION['authorised']) && $_SESSION['authorised'] == true)
{   
    if(isset($_SESSION['type']))
    {
        if($_SESSION['type'] == 'administrator')
        {
			include ('connection.inc');
			$action_string = $_POST['action'];
			$action_parts = explode(" ", $action_string);
			$action =  $action_parts[0];
			$announcement_id = $action_parts[1];
			
			if ($action=='Delete')
			{
				$sql="Delete from announcements where announcement_id=$announcement_id";
				$result=pg_query($sql);
				header('Location:admin_manageannouncements.php');
				exit();
			}		
			elseif($action=='View')
			{

				$_SESSION['view_announcement']=$announcement_id;
				header('Location:admin_viewannouncement.php');
				exit();
			}
			elseif($action=='Edit')
			{

				$_SESSION['edit_announcement']=$announcement_id;
				header('Location:admin_editannouncement.php');
				exit();
			}			
			
        }
        elseif($_SESSION['type'] == 'student')
        {
            header('Location: student_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'tutor')
        {
            header('Location: tutor_index.php');
            exit();
        }
        elseif($_SESSION['type'] == 'parent')
        {
            header('Location: parent_index.php');
            exit();
        }
    }
}
else
{
    header('Location: index.php');
}
?>
